<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">{{data.title}}</block>
		</cu-custom>
		<view class="text-empty solid-top text-center" v-if="data.records.length==0">
			<text class="text-lg">空空如也</text>
		</view>
		<view class="records solid-top" v-else>
			<view class="cu-card article">
				<view @click="naviTo('lesson/detail',{id:item.id})" class="cu-item shadow" v-for="(item, index) in data.records" :key="index">
					<view class="content">
						<image :src="item.imgurl" mode="aspectFill"></image>
						<view class="desc">
							<view class="title">
								<view>{{item.coursebrief}}</view>
							</view>
							<view class="text-content" v-if="item.timeline">上次阅读到{{item.title}}</view>
							<view class="text-content" v-else>{{item.title}}</view>
							<view>
								<view class="cu-tag bg-red light sm round">上次学习到{{item.date}}秒</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<uni-load-more class="bg-white" :status="loadmore" :contentText="contentText"></uni-load-more>
		</view>
	</view>
</template>

<script>
	import core from "@/static/core.js"
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue"
	
	export default {
		components: {uniLoadMore},
		data() {
			return {
				page:1,
				loadmore:'more',
				contentText:{
					"contentdown":"上滑加载更多数据",
					"contentrefresh":"加载中...",
					"contentnomore":"就这么多了~"
				},
				data:{
					title:"学习记录",
					records:[]
				}
			}
		},
		onLoad() {
			if(core.userinfo.uid<=0) return core.toast('请先登录','login');
			var that = this;
			this.initData('member/record',{},function(res){
				that.loadmore = res.records.length<15 ? 'noMore' : 'more';
			});
		},
		onReachBottom() {
			if(this.loadmore=='noMore') return false;
			var that = this;
			return core.get('member/record',function(res){
				that.data.records = that.data.records.concat(res.records);
				that.loadmore = res.records.length<15 ? 'noMore' : 'more';
				that.page += 1;
			},{page:this.page+1});
		},
		methods:{
			initData(route, data={}, callback=false){
				var that = this;
				(this.$api.reqGet({
					url:"menu/selLogByUid/"+core.userinfo.uid
				}).then(res=>{
					console.log(res)
					if(res.code==200){
						that.data.records=res.data;
					}
					console.log(that.data.records)
				}))
				// core.get(route,function(res){
				// 	if(typeof(res.message)!='undefined' && typeof(res.type)!='undefined'){
				// 		return core.report(res, true);
				// 	}
				// 	that.data = res;
				// 	uni.setNavigationBarTitle({
				// 		title:res.title
				// 	});
				// 	if(callback){
				// 		callback(res);
				// 	}
				// },data);
			},
			naviTo(page,data={}){
				console.log(data)
				return core.navito(page,data);
			},
			unSupport(){
				return core.toast('敬请期待');
			}
		}
	}
</script>

<style>
</style>
